<?php

namespace App\Models\Applet\Order;

class ShopOrderExpressModel extends BaseOrderModel
{
    protected $table = 'shop_order_express';

    const STATUS_WAIT_DELIVERY = 0; // 待发货
    const STATUS_DELIVERY      = 1; // 已发货
    const STATUS_DELIVERED     = 2; // 已收货

    /**
     *
     * @param int $orderMasterId
     * @param array $fields
     * @return array
     */
    public function getItemByOrderMasterId(int $orderMasterId, array $fields = self::QUERY_DEFAULT_FIELDS): array
    {
        $result = $this->select($fields)
                       ->where('order_master_id', $orderMasterId)
                       ->where('deleted', self::DELETED_NO)
                       ->first();
        return $result ? $result->toArray() : [];
    }

    /**
     *
     * @param array $orderMasterIds
     * @param array $fields
     * @return array
     */
    public function getItemByOrderMasterIds(array $orderMasterIds, array $fields = self::QUERY_DEFAULT_FIELDS): array
    {
        return $this->select($fields)
                    ->whereIn('order_master_id', $orderMasterIds)
                    ->where('deleted', self::DELETED_NO)
                    ->get()
                    ->toArray();
    }

    /**
     * 根据订单号查询数据
     * @return void
     */
    public function getItemByExpressNo(string $expressNo, array $fields = self::QUERY_DEFAULT_FIELDS): array
    {
        $result = $this->select($fields)
                       ->where('express_no', $expressNo)
                       ->where('deleted', self::DELETED_NO)
                       ->first();

        return $result ? $result->toArray() : [];
    }
}
